package com.t3.tuio
{
	import flash.events.Event;
	import com.t3.client.T3Client;
	
	public class TUIOEvent extends Event
	{
		public static const ADD_TUIO_OBJ:String 	= "addTuioObj";
		public static const UPDATE_TUIO_OBJ:String 	= "updateTuioObj";
		public static const REMOVE_TUIO_OBJ:String 	= "removeTuioObj";
		
		public static const ADD_TUIO_CUR:String		= "addTuioCur";
		public static const UPDATE_TUIO_CUR:String 	= "updateTuioCur";
		public static const REMOVE_TUIO_CUR:String	= "removeTuioCur";
		
		public static const CURSOR_MOVED:String		= "cursorMoved";
		
		public static const REFRESH:String			= "refresh";
		
		private static var ids:uint = 0;
		
		public var data:Object;
		public var s_id:uint;
		public var f_id:uint;
		public var x:Number;
		public var xStage:Number;
		public var y:Number;
		public var yStage:Number;
		public var a:Number;
		public var dx:Number;
		public var dy:Number;
		public var da:Number;
		public var point:TUIOPoint;
		public var id:uint;
		
		public function TUIOEvent( type:String, data:Object = null )
		{
			super( type );
			
			this.data = data;
			this.id = ids++;
			
			if( data != null )
			{	
				if( hasProp( "f_id" ) )
				{
					f_id = data.f_id;
				}
				
				if( hasProp( "s_id" ) )
				{
					s_id = data.s_id;
				}
				
				if( hasProp( "a" ) )
				{
					a = data.a;
				}
				
				if( hasProp( "da" ) )
				{
					da = data.da;
				}
				
				if( hasProp( "x" ) )
				{
					x = data.x;
					xStage = x * T3Client._width;
				}
				
				if( hasProp( "y" ) )
				{
					y = data.y;
					yStage = y * T3Client._height;
				}
				
				if( hasProp( "dx" ) )
				{
					dx = data.dx;
				}
				
				if( hasProp( "dy" ) )
				{
					dy = data.dy;
				}
				
				if( hasProp( "point" ) )
				{
					point = data.point;
				}
			}
		} 
		
		private function hasProp( prop:String ):Boolean
		{
			return data.hasOwnProperty( prop );
		}
		
		public override function clone():Event
		{
			return new TUIOEvent( type, data );
        }
	}
}